/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.pixlib.sfe.view 
{
	import net.pixlib.plugin.Plugin;
	import net.pixlib.sfe.util.getTranslation;
	import net.pixlib.sfe.view.abstract.AsWingView;
	import net.pixlib.sfe.view.editor.EditorView;
	import net.pixlib.sfe.view.editor.MenubarView;
	import net.pixlib.sfe.view.editor.StatusbarView;
	import net.pixlib.tms.LocalManager;
	import net.pixlib.tms.LocalManagerEvent;

	import org.aswing.BorderLayout;
	import org.aswing.JOptionPane;
	import org.aswing.JPanel;

	import flash.events.Event;

	/**
	 * Main application views layout.
	 * 
	 * @author Romain Ecarnot
	 */
	public class MainView extends AsWingView 
	{
		//--------------------------------------------------------------------
		// Public API
		//--------------------------------------------------------------------
		
		/**
		 * Creates view.
		 */
		public function MainView(owner : Plugin)
		{
			super(owner, ViewList.MAIN_VIEW, new JPanel(new BorderLayout(5, 5)));
		}
		
		
		//--------------------------------------------------------------------
		// Protected methods
		//--------------------------------------------------------------------
		
		/**
		 * Inits User Interface.
		 */
		override protected function onInitView( ) : void
		{
			LocalManager.getInstance().addEventListener(LocalManagerEvent.onLocalChangeEVENT, _onLocalChangeHandler);
			
			var menubar : AsWingView = new MenubarView(getOwner());
			getPanel().append(menubar.getComponent(), BorderLayout.NORTH);
			
			var editor : AsWingView = new EditorView(getOwner());
			getPanel().append(editor.getComponent(), BorderLayout.CENTER);
			
			var statusbar : StatusbarView = new StatusbarView(getOwner());
			getPanel().append(statusbar.getComponent(), BorderLayout.SOUTH);
			
			_onLocalChangeHandler();
			
			super.onInitView();
		}
		
		/**
		 * Returns view content as AsWing JPanel.
		 */
		protected function getPanel() : JPanel
		{
			return getComponent() as JPanel;	
		}
		
		
		//--------------------------------------------------------------------
		// Private methods
		//--------------------------------------------------------------------
		
		/** @private */
		private function _onLocalChangeHandler(event : Event = null) : void
		{
			JOptionPane.CANCEL_STR = getTranslation("cancel");			JOptionPane.CLOSE_STR = getTranslation("close");			JOptionPane.NO_STR = getTranslation("no");			JOptionPane.OK_STR = getTranslation("ok");			JOptionPane.YES_STR = getTranslation("yes");
		}
	}
}
